import { userApi } from '/api/user'
import { $utils } from '/utils'

Page({
  data: {
    offset: 0,
    list: [],
    nomore: false,
  },
  async onLoad() {
    this.getlist()
  },
  async getlist() {
    if (this.data.nomore) return
    const list = await userApi.withdrawList({ limit: 15, offset: this.data.offset })
    this.setData({
      list,
      nomore: list.length < 15,
      offset: $utils.getLastField(list),
    })
  },
  onReachBottom() {
    this.getlist()
  },
  onPullDownRefresh() {
    this.setData({
      offset: 0,
      nomore: false,
    })
    this.getlist()
  },
  /** 详情 */
  toDetail(e: WechatMiniprogram.CustomEvent) {
    const {
      currentTarget: {
        dataset: { index },
      },
    } = e
    wx.navigateTo({
      url: `/mine/withdrawDetail/withdrawDetail?index=${index}`,
    })
  },
})
